package com.tjsinfo.tjsoa.worklog.bo;

import java.util.List;

import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.worklog.dao.IWorkLogExamineDao;
import com.tjsinfo.tjsoa.worklog.dao.WorkLogExamineDao;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogExamine;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogMain;


public class WorkLogExamineBo implements IWorkLogExamineBo{

	private IWorkLogExamineDao workLogExamineDao;
	final Integer daipishi = 0;
	private final Integer yipishi = 1;
	final Boolean starttrue = true;
	final Boolean startfalse = false;	
	

	public IWorkLogExamineDao getWorkLogExamineDao() {
		return workLogExamineDao;
	}

	public void setWorkLogExamineDao(IWorkLogExamineDao workLogExamineDao) {
		this.workLogExamineDao = workLogExamineDao;
	}

	public boolean addShangBaoRen(String shangbaoren, String jihuaid) {
		// TODO Auto-generated method stub
		try {
			String[] strarrry =	ToolKit.splitString(shangbaoren);
			if (strarrry[0] != null) {
				for (String string : strarrry) {
					WorkLogExamine workLogExamine = new WorkLogExamine();
					workLogExamine.setExamineState(daipishi);
					WorkLogMain logMain = new WorkLogMain();
					logMain.setId(jihuaid);
					workLogExamine.setWorkLogMain(logMain);
					TSystemUser tjsUser = new TSystemUser();
					tjsUser.setUserId(Integer.parseInt(string));
					workLogExamine.setTjsUser(tjsUser);
					workLogExamine.setExamineContent("");
					workLogExamineDao.save(workLogExamine);
					
				}
				
			} else {
				;
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return startfalse;
		}
		return startfalse;
	}

	public void delete(WorkLogExamine workLogDefine) {
		// TODO Auto-generated method stub
		workLogExamineDao.delete(workLogDefine);
	}

	public String save(WorkLogExamine workLogDefine) {
		// TODO Auto-generated method stub
		return workLogExamineDao.save(workLogDefine);
	}

	public boolean saveORupdateWorkLog(Integer userid, String jihuaid,
			String value) {
		// TODO Auto-generated method stub
		try {
			/*WorkLogExamine workLogExamine =	selectWorkLog(userid, jihuaid);
			if (workLogExamine != null ) {
				workLogExamine.setExamineContent(value);
				workLogExamine.setExamineState(1);
				workLogExamineDao.update(workLogExamine);
			} else {*/
			WorkLogExamine  workLogExamine = new WorkLogExamine();
				workLogExamine.setExamineContent(value);
				workLogExamine.setExamineState(1);
				TSystemUser tjsUser = new TSystemUser();
				tjsUser.setUserId(userid);
				workLogExamine.setTjsUser(tjsUser);
				WorkLogMain workLogMain = new WorkLogMain();
				workLogMain.setId(jihuaid);
				workLogExamine.setWorkLogMain(workLogMain);
				workLogExamineDao.save(workLogExamine);
			//}
			return starttrue;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return startfalse;
		}
	}

	public List selectSuddenlyWorkLog(Integer userid, Integer start) {
		// TODO Auto-generated method stub
		return 	workLogExamineDao.selectSuddenlyWorkLog(userid, start);
	}

	public WorkLogExamine selectWorkLog(Integer userid, String jihuaid) {
		// TODO Auto-generated method stub
		
		return workLogExamineDao.selectWorkLog(userid, jihuaid);
	}

	public void update(WorkLogExamine workLogDefine) {
		// TODO Auto-generated method stub
		workLogExamineDao.update(workLogDefine);
	}
	
}
